package com.gid.rcflightlogger;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class CycleListAdapter extends ArrayAdapter<Cycle> 
{
	private LayoutInflater mInflater;
	Context mContext;
	
	public CycleListAdapter(Context context) {
		super(context, 0);
		mContext = context;
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Cycle cycle = getItem(position);
		
		//reuse view if possible
		View v = convertView;
		if (v == null) {
			v = mInflater.inflate(R.layout.layout_batterylogbrowse_listitem, null);
		}
		
		//fillout the view
		final TextView nameView = (TextView) v.findViewById(R.id.batterylogbrowse_listitem_name);
		if (nameView != null)
		{
			nameView.setText(myUtils.DateTime2Str(cycle.getDate()) + "    " + cycle.getBattery(mContext).getTag());
		}

		final TextView dataView = (TextView) v.findViewById(R.id.batterylogbrowse_listitem_data);
		if (dataView != null)
		{
			dataView.setText(myUtils.Duration2Str(cycle.getDuration(), false));
		}
		
		return v;
	}

	@Override
	public long getItemId(int position) {
		return getItem(position).getId();
	}

}
